<template>
	<view class="content">
		<view class="myAddress">
		<view class="fbc">
			<h5>我的位置</h5>
			<view class="tioajian" v-if="vuex_select" style="color: #FF8D5F;font-size: 24rpx;">
			<text v-if="vuex_select.cityName">{{vuex_select.cityName}}/</text>
			<text v-if="vuex_select.countName">{{vuex_select.countName}}/</text>
			<text v-if="vuex_select.genderName">{{vuex_select.genderName}}/</text>
			<text v-if="vuex_select.teacherTypeName">{{vuex_select.teacherTypeName}}/</text>
			<text v-if="vuex_select.stageName">{{vuex_select.stageName}}/</text>
			<text v-if="vuex_select.subjectName">{{vuex_select.subjectName}}</text>
			</view>
		</view>
			<view class="poastion">
				<view class="aes" >
					<image src="/static/image/address.png" mode=""></image>
					<text>{{citys}}</text>
				</view>
				<view class="diqu">
					<view class="leibie">
						<view class="q" :class="current===index ? 'blue' :'border'" @click="changeCate(index,item.id)"
							v-for="(item,index) in leibie" :key="index">
							{{item.name}}
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="type">
			<h5>老师类型</h5>
			<view class="teacher">
				<view style="padding: 0 100rpx;border-bottom: 1px solid #E5E5E5;">
					<u-tabs active-color="#FF6E56" nactive-color="#333333" :list="list" :is-scroll="false"
						:current="current1" @change="change"></u-tabs>
				</view>
				<view class="diqu" style="margin-top: 50rpx;">
					<view class="leibie">
						<view :class="current2===index ? 'blue' :'border'" @click="changeCate1(index,item.id)"
							v-for="(item,index) in type" :key="index">
							{{item.categoryName}}
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="subject">
			<h5>科目类型</h5>
			<view class="teacher">
				<view style="border-bottom: 1px solid #E5E5E5;">
					<u-tabs active-color="#FF6E56" nactive-color="#333333" :list="list1" :is-scroll="false"
						:current="current3" @change="change1"></u-tabs>
				</view>
				<view class="diqu" style="margin-top: 50rpx;">
					<view class="leibie">
						<view :class="current4===index ? 'blue' :'border'" @click="changeCate2(index,item.id)"
							v-for="(item,index) in subject" :key="index">
							{{item.categoryName}}
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="foot">
			<view class="sub">
				<view class="left" @tap="reset">
					重置
				</view>
				<view class="right" @tap="submit">
					确定
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				current: null,
				current1: 0,
				current2: null,
				current3: 0,
				current4: null,
				citys: '',
				parentId: '',
				leibie: [],
				type: [],
				subject: [{
						name: '小学语文'
					},
					{
						name: '小学数学'
					},
					{
						name: '小学奥数'
					},
					{
						name: '小学英语'
					},
					{
						name: '小学拼音'
					},
				],
				list: [{
					name: '男女不限'
				}, {
					name: '男老师'
				}, {
					name: '女老师',
				}],
				list1: [],
				cityList: [],
				form: {
					cityId: '',
					gender: '',
					subjectId: '',
					teacherType: '',
					countyId: '',
					cityName: '',
					countName: '',
					genderName: '',
					teacherTypeName: '',
					stageName: '',
					stageId: '',
					subjectName: ''
				},
				types: ''
			};
		},
		onShow() {
			this.citys = uni.getStorageSync('citys')
			this.getCity()
		},
		onLoad(options) {
			this.types = options.types
			if (this.vuex_select) {
				console.log('ddddddddddddddd', this.vuex_select)
			}
			this.teacherType()
			this.jieduan()
		},
		methods: {
			async getCity() {
				const res = await this.$u.api.getCity({
					cityName: this.citys
				})
				// this.form.cityId = res[0].id

				const resq = await this.$u.api.getQuyu({
					parentId: res[0].id
				})
				this.leibie = resq
				if (this.vuex_select.countyId) {
					this.form.countyId = this.vuex_select.countyId
					this.leibie.map((item, index) => {
						if (item.id == this.form.countyId) {
							this.current = index
						}
					})
				}
			},
			async teacherType() {
				this.type = await this.$u.api.getCate({
					categoryType: 1
				})
				// this.form.teacherType = this.type[0].id
				this.current2 = null
				this.current1 = 0
				if (this.vuex_select.teacherType) {
					this.form.teacherType=this.vuex_select.teacherType
					this.type.map((item, index) => {
						if (item.id == this.vuex_select.teacherType) {
							this.current2 = index
						}
					})
				}
				if(this.vuex_select.gender!=null){
					this.form.gender=this.vuex_select.gender
					if(this.form.gender==0){
						this.current1=0
					}
					if(this.form.gender==1){
						this.current1=1
					}
					if(this.form.gender==2){
						this.current1=2
					}
					console.log('sss')
				}
			},
			async jieduan() {
				this.list1 = await this.$u.api.getCateTree({
					categoryType: 2
				})
				this.list1.map(item => {
					console.log(item);
					item.name = item.categoryName
				})
				this.subject = this.list1[this.current3].categoryVOList
				this.form.stageId = this.list1[this.current3].id
				// this.form.subjectId = this.subject[0].id
				this.current4 = null
				this.current3=0
				if (this.vuex_select.subjectId) {
					// 小学初中高中
					this.form.stageId=this.vuex_select.stageId
					this.form.subjectId=this.vuex_select.subjectId
					this.list1.map((item, index) => {
						if (this.form.stageId == item.id) {
							this.current3 = index
							this.subject = this.list1[this.current3].categoryVOList
						}
					})
					// 年级
					this.subject.map((item,index)=>{
						if(this.form.subjectId==item.id){
							this.current4=index
						}
					})
				} 
			},
			goCity() {
				uni.navigateTo({
					url: '/pagesShop/address/address'
				})
			},
			changeCate(index, id) {
				if(this.current==index){
					this.current = null
					this.form.countyId = ''
				}
				else{
					this.current = index
					this.form.countyId = id
				}
			},
			changeCate1(index, id) {
				console.log(index);
				if(this.current2==index){
					this.current2 = null
					this.form.teacherType = ''
				}
				else{
					this.current2 = index
					this.form.teacherType = id
				}
			},
			changeCate2(index, id) {
				if(this.current4==index){
					this.form.subjectId = ''
					this.current4 = null
					
				}
				else{
					this.form.subjectId = id
					this.current4 = index
					
				}
			},
			change(index) {
				this.current1 = index;
				this.form.gender = index
			},
			change1(index) {
				this.current3 = index;
				this.form.stageId=this.list1[this.current3].id
				this.subject=[]
				this.subject=this.list1[this.current3].categoryVOList
				this.current4 = null
				// this.subject = []
				// this.jieduan()
			},
			// 重置
			reset() {
				console.log(11);
				this.current = null
				this.current1 = 0
				this.current2 = null
				this.current3 = 0
				this.current4 = null

				if (this.types == 1) {
					this.$u.vuex('vuex_sel', '')
				} else {
					this.$u.vuex('vuex_select', '')
					this.citys = uni.setStorageSync('')
				}
				uni.navigateBack({
					delta: 1
				})
			},
			submit() {

				if (this.types == 1) {
					this.$u.vuex('vuex_sel', this.form)
				} else {
					this.form.cityName=this.citys
					if(this.current){
						this.form.countName=this.leibie[this.current].name
					}
					if(this.current1){
						this.form.genderName=this.form.gender==0?'男女不限':this.form.gender?'男':'女'
					}
					if(this.current2){
						this.form.teacherTypeName=this.type[this.current2].categoryName
					}
					if(this.current3){
							this.form.stageName=this.list1[this.current3].categoryName
					}
					if(this.current4){
							this.form.subjectName=this.subject[this.current4].categoryName
					}
					
					this.$u.vuex('vuex_select', this.form)
				}

				uni.navigateBack({
					delta: 1
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f2f2f2;
	}

	h5 {
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #333333;
	}

	.content {
		padding-bottom: 90rpx;
	}


	.diqu {


		.leibie {
			.q {
				margin-right: 34rpx;
				padding: 0 20rpx;

				&:nth-child(4n) {
					// margin-right: 0;
				}
			}

			text-align: center;
			line-height: 60rpx;
			margin-top: 20rpx;
			display: flex;
			align-items: center;
			flex-wrap: wrap;

			view {
				// width: 150rpx;
				// height: 57rpx;
				// width: calc(21% - 6rpx);

				margin-top: 20rpx;

				&:nth-child(4) {
					// margin-right: 0;
				}
			}

			.blue {
				margin-right: 34rpx;
				padding: 0 20rpx;
				text-align: center;
				line-height: 60rpx;
				// width: 132rpx;
				// height: 60rpx;
				background: #FFFFFF;
				border: 1px solid #FF6A55;
				border-radius: 30rpx;
				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #FF6B55;
			}

			.border {
				margin-right: 34rpx;
				padding: 0 20rpx;
				// width: 132rpx;
				// height: 60rpx;
				background: #EEEEEE;
				border-radius: 30rpx;
				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #333333;
			}
		}
	}

	.myAddress {
		margin-top: 46rpx;
		padding: 0 30rpx;

		.poastion {
			padding: 0 30rpx 30rpx 40rpx;
			margin-top: 30rpx;
			// height: 268rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 0rpx 38rpx 0rpx rgba(145, 145, 145, 0.07);
			border-radius: 20rpx;

			.aes {
				padding-top: 50rpx;
				display: flex;
				align-items: center;

				image {
					width: 26rpx;
					height: 34rpx;
					margin-right: 15rpx;
				}
			}


		}
	}

	.type {
		margin-top: 60rpx;
		padding: 0 30rpx;

		/deep/.u-tab-bar {
			width: 140rpx !important;
			height: 4rpx !important;
			background-color: transparent !important;
			background: linear-gradient(90deg, #FF8D5F, #FF6A55);
			left: -57rpx;
			bottom: -4rpx !important;
		}

		.teacher {
			padding: 0 18rpx 42rpx;
			margin-top: 26rpx;
			// height: 286rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
		}
	}

	.subject {
		margin-top: 60rpx;
		padding: 0 30rpx;

		.teacher {
			padding: 0 18rpx 42rpx;
			margin-top: 23rpx;
			// height: 380rpx;
			background: #FFFFFF;
			border-radius: 20rpx;

			/deep/.u-tab-bar {
				width: 90rpx !important;
				height: 4rpx !important;
				background-color: transparent !important;
				background: linear-gradient(90deg, #FF8D5F, #FF6A55);
				left: -24rpx;
				bottom: -2rpx !important;
			}
		}
	}

	.foot {
		padding: 0 110rpx;
		margin-top: 60rpx;

		.sub {
			display: flex;
			align-items: center;
			justify-content: space-between;

			.left {
				width: 235rpx;
				height: 80rpx;
				background: #F2F2F2;
				border: 1px solid #FF7157;
				border-radius: 40rpx;
				text-align: center;
				line-height: 80rpx;
				font-size: 34rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #FF6C55;
			}

			.right {
				width: 235rpx;
				height: 80rpx;
				background: linear-gradient(-90deg, #FF8D5F, #FF6A55);
				border-radius: 40rpx;
				text-align: center;
				line-height: 80rpx;
				font-size: 34rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #FFFFFF;
			}
		}
	}
</style>